package cn.com.css.taxInspection.workflow.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;

import java.util.Date;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import cn.com.css.taxInspection.common.constants.Constants;
import cn.com.css.taxInspection.common.result.DataResult;
import cn.com.css.taxInspection.gt3.service.DmGySwjgService;
import cn.com.css.taxInspection.system.service.impl.HttpSessionService;
import cn.com.css.taxInspection.util.TsBqUtils;
import cn.com.css.taxInspection.workflow.entity.WorkflowGreetEntity;
import cn.com.css.taxInspection.workflow.service.WorkflowGreetService;

import com.baomidou.mybatisplus.core.metadata.IPage;

import io.swagger.annotations.ApiOperation;

/**
 * ${comments}
 *
 * @author shaochangyang
 * @email l2l84o7o5@live.com
 * @date 2023-10-16 10:54:31
 */
@Controller
@RequestMapping("/workflow/greet")
public class WorkflowGreetController {
	@Autowired
	private WorkflowGreetService workflowGreetService;
	@Autowired
	private HttpSessionService httpSessionService;
	@Autowired
	private DmGySwjgService dmGySwjgService;
	
	/**
	 * 
	 * @param workflowGreet
	 * @return
	 */
	@ApiOperation(value = "新增")
	@PostMapping("/write")
	@RequiresPermissions("workflow:greet:write")
	@ResponseBody
	public DataResult add(@RequestBody WorkflowGreetEntity workflowGreet) {
		Date date = new Date();
		String greetMan = workflowGreet.getGreetMan();
		if(TsBqUtils.isNull(greetMan)){
			return DataResult.fail("打招呼人不能为空："+greetMan);
		}
		
		String greetOrg = workflowGreet.getGreetOrg();
		if(TsBqUtils.isNull(greetOrg)){
			return DataResult.fail("打招呼单位不能为空："+greetOrg);
		}
		
		String greetFile = workflowGreet.getGreetFile();
		if(TsBqUtils.isNull(greetFile)){
			return DataResult.fail("打招呼相关案卷不能为空："+greetFile);
		}
		
		String greetDate = workflowGreet.getGreetDate();
		if(TsBqUtils.isNull(greetDate)){
			return DataResult.fail("打招呼日期不能为空："+greetDate);
		}
		
		String greetConcent = workflowGreet.getGreetConcent();
		if(TsBqUtils.isNull(greetConcent)){
			return DataResult.fail("打招呼相关内容不能为空："+greetConcent);
		}
		String CurrentUserId = httpSessionService.getCurrentUserId();
		String currentDeptId = httpSessionService.getCurrentDeptId();
		String sjswjgDm = dmGySwjgService.getSjswjgDm(currentDeptId);
		workflowGreet.setTaxorgcode(sjswjgDm);
		workflowGreet.setCreateId(CurrentUserId);
		workflowGreet.setCreateTime(date);
		workflowGreet.setDeleted(Constants.DATA_NOT_DELETED);
		workflowGreetService.save(workflowGreet);
		return DataResult.success();
	}

	/**
	 * 
	 * @param workflowGreet
	 * @return
	 */
	@SuppressWarnings({ "unchecked", "rawtypes" })
	@ApiOperation(value = "查询分页数据")
	@PostMapping("/list")
	@RequiresPermissions("workflow:greet:list")
	@ResponseBody
	public DataResult list(@RequestBody WorkflowGreetEntity workflowGreet) {
		String CurrentUserId = httpSessionService.getCurrentUserId();
		Page page = new Page(workflowGreet.getPage(), workflowGreet.getLimit());
		LambdaQueryWrapper<WorkflowGreetEntity> queryWrapper = Wrappers.lambdaQuery();
		// 查询条件示例
		queryWrapper.eq(WorkflowGreetEntity::getCreateId, CurrentUserId);
		IPage<WorkflowGreetEntity> iPage = workflowGreetService.page(page, queryWrapper);
		return DataResult.success(iPage);
	}

	@SuppressWarnings({ "rawtypes", "unchecked" })
	@ApiOperation(value = "查询分页数据")
	@PostMapping("/list1")
	@RequiresPermissions("workflow:greet:list1")
	@ResponseBody
	public DataResult list1(@RequestBody WorkflowGreetEntity workflowGreet) {
		String currentDeptId = httpSessionService.getCurrentDeptId();
		String sjswjgDm = dmGySwjgService.getSjswjgDm(currentDeptId);
		Page page = new Page(workflowGreet.getPage(), workflowGreet.getLimit());
		LambdaQueryWrapper<WorkflowGreetEntity> queryWrapper = Wrappers.lambdaQuery();
		// 查询条件示例
		queryWrapper.like(WorkflowGreetEntity::getTaxorgcode, sjswjgDm);
		IPage<WorkflowGreetEntity> iPage = workflowGreetService.page(page, queryWrapper);
		return DataResult.success(iPage);
	}

}
